package syncOH

import (
	"golang.org/x/crypto/ssh"
	"log"
	"test/unit_function/sshdata"
)

const (
	OpenHarmony40Beta1 = "OpenHarmony-4.0-Beta1"
	Default            = "default"
)

// SyncCode 同步代码的功能：1.上传脚本 2.执行脚本 3.返回结果
func SyncCode(version string, client *ssh.Client) error {
	// 1.上传脚本
	result := sshdata.UploadFile("/mnt/data/ywx1293154/script_sync.sh", "D:/auto_test/test_script_for_openharmony/script/script_sync.sh", client, "0744")
	if !result {
		log.Println("syncOH upload file failed")
	}
	log.Println("syncOH upload sync file success. start sync..., branch=", version)
	// 2.执行脚本
	session, err := client.NewSession()
	if err != nil {
		log.Println("syncOH create Session Err:", err)
	}
	defer session.Close()
	if err := session.Run("~/script_sync.sh " + version + " > ~/script_sync.log"); err != nil {
		log.Println("syncOH Failed to run: " + err.Error())
		return err
	}
	log.Println("syncOH success branch=", version)
	return nil
}
